
package com.yimixian.app.adapter;

import com.yimixian.app.R;
import com.yimixian.app.model.ValidatedOrder;
import com.yimixian.app.viewholder.ChooseCouponViewHolder;
import com.ymx.sdk.widget.recyclerview.viewholder.AbsViewHolder;
import com.ymx.sdk.widget.recyclerview.ListRecyclerAdapter;

import android.content.Context;
import android.view.ViewGroup;

import java.util.ArrayList;

public class ChooseCouponRecyclerAdapter extends ListRecyclerAdapter<ValidatedOrder.Bonus> {

    public ChooseCouponRecyclerAdapter(ArrayList<ValidatedOrder.Bonus> datas, Context context) {
        super(datas, context);
    }

    @Override
    public int getItemLayoutResId() {
        return R.layout.adapter_coupon_item;
    }

    @Override
    public AbsViewHolder getItemViewHoler(ViewGroup parent, int viewType) {
        return new ChooseCouponViewHolder(getItemView(parent, viewType), mContext);
    }

    public ArrayList<ValidatedOrder.Bonus> setSelectItem(int pos) {
        boolean isChecked = mList.get(pos).isChecked();
        for (int i = 0; i < mList.size(); i++) {
            mList.get(i).setChecked(false);
        }
        mList.get(pos).setChecked(!isChecked);
        return mList;
    }

}
